/*
 * AbleBaker.java
 *
 * Created on October 22, 2007, 12:44 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ablebaker;

//import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;
import simulationengine.animation.AnimationCommand;
import simulationengine.animation.AnimationEngine;
import simulationengine.process.Producer;
import simulationengine.process.Resource;
import simulationengine.process.Distribution;

/**
 *
 * @author Eric Drucker
 */
public class AbleBaker
{
	
	/** Creates a new instance of AbleBaker */
	public AbleBaker()
	{
	}

	
	public static void main(String args[])
	{
            final int endOfSimulation = 100000;

            //Time Distributions
             Arrival arriveTimeDistribution = new Arrival();
             Able           ableTimeDistribution = new Able();
             Baker          bakerTimeDistribution = new Baker();
             Distribution   exitTimeStats = new Distribution();
                   
             //Resources
             Resource able = new Resource(ableTimeDistribution,0);
             Resource baker = new Resource(bakerTimeDistribution,1);
             
             Resource compositeResource = new Resource(2,null,false,false);
             compositeResource.nextAvailableResourceQ.put(able);
             compositeResource.nextAvailableResourceQ.put(baker);
             
		   //LinkedBlockingQueue<AnimationCommand> commands = new LinkedBlockingQueue<AnimationCommand>();
                   PriorityBlockingQueue<AnimationCommand> commands = new PriorityBlockingQueue<AnimationCommand>();
		   
             Producer callers = new Producer(endOfSimulation, arriveTimeDistribution, compositeResource, commands);
               
             System.out.println("Starting AbleBaker Simulation");

             callers.start();
             
		   int [] serviceLocations = {2};
		   AnimationEngine a = new AnimationEngine("Able Baker", commands, endOfSimulation, serviceLocations);

             //System.out.println("AbleBaker simulation completed");	
	}
        
        public static class Arrival extends simulationengine.process.Distribution
        {            
            public Arrival()
            {
                super();
            }
            
            public synchronized int next()
            {
                //Interarrival time
                randInt = rand.nextInt(100);
                if(randInt < 25)
                        time += 1;
                else if (randInt < 65)
                        time += 2;
                else if (randInt < 85)
                        time += 3;
                else 
                        time += 4;
                
                return time;
            }
        }
         
        public static class Able extends simulationengine.process.Distribution
        {
            public Able()
            {
                super();
            }
            
            public int next()
            {
                //Able service times
                randInt = rand.nextInt(100);
                if(randInt < 30)
                        time = 2;
                else if(randInt < 58)
                        time = 3;
                else if(randInt < 83)
                        time = 4;
                else
                        time = 5;
                
                return time;
            }
        }
        
        public static class Baker extends simulationengine.process.Distribution
        {
            public Baker()
            {
                super();
            }
            
            public int next()
            {
                //Baker service times
                randInt = rand.nextInt(100);
                if(randInt < 35)
                        time = 3;
                else if(randInt < 60)
                        time = 4;
                else if(randInt < 80)
                        time = 5;
                else
                        time = 6;
            
                return time;
            }
        }
}
